<template>
  <div class="role-list">
    <cg-table
      :get-list="getList"
      :delete-data="deleteData"
      :table-header="columns"
    >
      <div slot="operator" slot-scope="text, record">
        <a-button
          size="small"
          type="link"
          @click="handleRoleClick(record)"
          v-if="record.menuType !== '3'"
        >
          权限分配
        </a-button>
      </div>
    </cg-table>
    <cg-add-edit-modal
      :add-edit-form-data="addEditFormData"
      :get-data="getData"
      :create-data="createData"
      :update-data="updateData"
    />
  </div>
</template>

<script>
import CgTable from '@/components/cgTable/index.jsx';
import CgAddEditModal from '@/components/cgAddEditModal/CgAddEditModal';
// import MenuModal from '@/views/menuList/components/MenuModal';
import roleApi from '@/api/role';
import { columns, addEditFormData } from '@/mock/roleList';
import emitter from '@/utils/emitter';
import Events from '@/utils/event';

export default {
  name: 'RoleList',
  components: {
    CgAddEditModal,
    CgTable
  },
  data () {
    return {
      modalData: {
        record: {},
        type: ''
      },
      getList: roleApi.list,
      getData: roleApi.getDataById,
      createData: roleApi.add,
      updateData: roleApi.update,
      deleteData: roleApi.delete,
      columns,
      addEditFormData
    };
  },
  methods: {
    handleRoleClick (record) {
      console.log(record);
    }
  },
  created () {
    emitter.on(Events.SHOW_ADD_EDIT_MODAL, data => {
      console.log(data);
    });
  },
  beforeDestroy () {
    emitter.off(Events.SHOW_ADD_EDIT_MODAL);
  }
};
</script>

<style scoped>

</style>
